package org.mspring.platform.security.service;

import org.mspring.platform.security.dao.UserRoleDao;
import org.mspring.platform.security.entity.UserRole;
import org.mspring.platform.security.entity.UserRolePK;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Gao Youbo
 * @since 2014年3月8日
 */
@Service
@Transactional
public class UserRoleService {

    @Autowired
    private UserRoleDao userRoleDao;

    public void createUserRole(long userId, long roleId) {
        userRoleDao.insert(new UserRole(new UserRolePK(userId, roleId)));
    }

    public void createUserRole(long userId, String... roles) {
        for (String role : roles) {
            this.createUserRole(userId, Long.valueOf(role));
        }
    }
}
